import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;

/**
 * 
 */

/**
 * @author Yungoo Kim, Yong Woo Lee
 *
 */
public class Hanoi extends UiApplication {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Hanoi _game = new Hanoi();
		_game.enterEventDispatcher(); 
		//TODO Change the SDK Version to 5.0. Current on 4.0
	}
	
	public Hanoi() {
		//pushScreen(new GameScreen());	
		
		pushScreen(new CreateMenuScreen());

	}
	
}

class CreateMenuScreen extends MainScreen implements FieldChangeListener {
	
	BasicEditField bef = new BasicEditField("Specify the number of blocks you would like. (3~8) : ", "");
	ButtonField mySubmitButton = new ButtonField("Submit");
	
	public CreateMenuScreen()
    {
      add(new RichTextField("Created by Yong Woo Lee, Yungoo Kim"));
      add(new SeparatorField());
      add(bef);
      add(mySubmitButton);
      mySubmitButton.setChangeListener(this);
    }
    
    public void close()
    {
        Dialog.alert("Goodbye!");     
        super.close();
    }

	public void fieldChanged(Field field, int context) {
		if (field == mySubmitButton){
			
			try {
        		int a = Integer.parseInt(bef.getText());
        		if (a > 2 && a < 9){
        			UiApplication.getUiApplication().pushScreen(new GameScreen(a));
        		} else {
        			Dialog.alert("Enter numeric 3~8");
        		}
        	} catch (NumberFormatException e){
        		Dialog.alert("Enter numeric 3~8");
        	}
		}
	}
}
